package com.pubinfo.passbook.common.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.pubinfo.passbook.common.model.bo.SubsidiaryDepartment;
import com.pubinfo.passbook.common.model.dto.role.RoleEditDTO;
import com.pubinfo.passbook.common.model.vo.system.UserRoleVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@NoArgsConstructor
@TableName(value = "t_system_role")
@ApiModel(value = "TSystemRole", description = "角色属性")
public class TSystemRole implements Serializable {
  
  @TableId(type = IdType.AUTO, value = "id")
  protected Integer id;
  @ApiModelProperty("角色名")
  protected String roleName;//角色名
  /**
   *
   */
  @ApiModelProperty("角色代码")
  protected String roleCode;//角色名
  protected String remark; //备注
  
  /**
   *
   */
  @ApiModelProperty("区县id")
  protected String districtId;
  @ApiModelProperty("公司代码")
  protected String nsrsbh;
  @ApiModelProperty("是否删除")
  protected int isdel; //是否删除
  /**
   * 创建时间
   */
  @TableField(fill = FieldFill.INSERT)
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  protected Date createTime;
  
  public TSystemRole(SubsidiaryDepartment info) {
    this.nsrsbh = info.getNsrsbh();
    this.districtId = info.getDistrictId();
    this.roleCode = "passbook_reimbursement_clerk";
    this.roleName = info.getName() + "-" + info.getDepartmentName() + "-部门报账员";
  }
  
  public static List<UserRoleVo> toList(List<TSubsidiaryInfo> infos) {
    List<UserRoleVo> roleList = new ArrayList<>();
    if (!CollectionUtils.isEmpty(infos)) {
      infos.stream().forEach(subsidiaryInfo -> {
        UserRoleVo systemRole = new UserRoleVo(subsidiaryInfo);
        roleList.add(systemRole);
      });
    }
    return roleList;
    
  }
  
  public static List<TSystemRole> convertVo(List<UserRoleVo> voList) {
    List<TSystemRole> roleList = new ArrayList<>();
    if (!CollectionUtils.isEmpty(voList)) {
      voList.stream().forEach(vo -> {
        roleList.add(vo);
      });
    }
    return roleList;
  }
  
  public TSystemRole(RoleEditDTO dto) {
    BeanUtils.copyProperties(dto, this);
  }
}
